#include <iostream>
#include <cstring>
using namespace std;

struct node
{
    char data;
    node *lchild=nullptr;
    node *rchild=nullptr;
};

string s1,s2;
int t=0;
int sun=1;

bool selve(node *T,int left,int right)
{
    if(left>=right)
    {
        T=nullptr;
        return false;
    }
    char c=s1[t];
    t++;
    int k=0;
    for(int i=left;i<right;i++)
    {
        if(s2[i]==c)
        {
            k=i;break;
        }
    }
    T=new node;
    T->data=c;
    bool t1=selve(T->lchild,left,k);
    bool t2=selve(T->rchild,k+1,right);
    if(t1||t2)
    {
        sun++;
    }
    return true;
}


int main() {
    int n;
    node *T;
    cin>>n>>s1>>s2;
    selve(T,0,n);
    cout<<sun;
    return 0;
}
